﻿using System;
using System.ComponentModel.Composition;
using System.Linq;

namespace NDBGen
{
    public abstract class GeneratorAttribute : ExportAttribute
    {
        public GeneratorAttribute(Type generatorForDescriptorType, Type descriptorContractType, Type generatorContractType)
            : base(generatorContractType)
        {
            if (generatorForDescriptorType.GetInterfaces().Any(i => i == descriptorContractType))
            {
                this.GeneratorForDescriptorType = generatorForDescriptorType;
                this.DescriptorContractType = descriptorContractType;
                this.GeneratorContractType = generatorContractType;
            }
            else throw new ArgumentException(String.Format("The specified generatorForDescriptorType must be an implementation of {0}", descriptorContractType.FullName), "generatorForDescriptorType");
        }

        public Type GeneratorForDescriptorType { get; private set; }

        public Type DescriptorContractType { get; private set; }

        public Type GeneratorContractType { get; private set; }
    }
}